package com.kly.user.db.dao.impl;

import com.fqgj.common.base.AbstractBaseMapper;
import com.google.common.collect.Maps;
import com.kly.user.db.dao.CustomersUserDao;
import com.kly.user.db.entity.CustomersUserEntity;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;

/**
 * User: yujianfu
 * Date: 2024-06-03
 * Time: 16:33:24.178
 */

@Repository
public class CustomersUserDaoImpl extends AbstractBaseMapper<CustomersUserEntity> implements CustomersUserDao {
    @Override
    public CustomersUserEntity getCustomer(String userCode) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("userCode", userCode);
        return this.getSqlSession().selectOne(this.getStatement("getCustomer"), params);
    }

    @Override
    public List<CustomersUserEntity> getCustomers(List<String> userCodes) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("userCodes", userCodes);
        return this.getSqlSession().selectList(this.getStatement("getCustomers"), params);
    }

    @Override
    public CustomersUserEntity addCustomersUser(String customerCode, String userCode) {
        CustomersUserEntity entity = new CustomersUserEntity();
        entity.setCustomerCode(customerCode);
        entity.setUserCode(userCode);
        return this.insert(entity);
    }

    @Override
    public Integer moveToNewCustomer(String newCustomerCode, String oldCustomerCode) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("newCustomerCode", newCustomerCode);
        params.put("oldCustomerCode", oldCustomerCode);
        return this.getSqlSession().update(this.getStatement("moveToNewCustomer"), params);
    }
}